package main

import (
	"log"
	"sync"
	"time"
)

var wg sync.WaitGroup
var signal = make(chan struct{}, 3)

func Producer(ch chan struct{}) {
	defer wg.Done()
	time.Sleep(3 * time.Second)
	ch <- struct{}{}
}

func Consumer(ch chan struct{}) {
	defer wg.Done()
	defer close(ch)
	for {
		select {
		case <-ch:
			log.Println("get signal")
			return
		default:
			log.Println("get null, waiting")
			time.Sleep(1 * time.Second)
		}
	}

}

func main() {
	wg.Add(2)
	go Producer(signal)
	go Consumer(signal)
	wg.Wait()
}
